#include <cmath>
#include <vector>

using namespace std;

class Solution {
public:
    vector<int> distributeCandies(int candies, int num_people) {
        int round = sqrt(2 * candies - 0.25) - 0.5;
        int left = candies - round * (round + 1) / 2;
        vector<int> ans(num_people);
        int row = round / num_people;
        int column = round % num_people;
        for (int i = 0; i < num_people; i++) {
            ans[i] = (2 * i + 2 + (row - 1) * num_people) * row / 2;
            if (i < column) {
                ans[i] += i + 1 + row * num_people;
            }
        }
        ans[column] += left;
        return ans;
    }
};
